import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;


public class Student {
	
	public  int Id;
	public String Name=null;
	public String Email=null;
	public String Phone=null; 
	public String course=null;
	public static JButton ViewTran		=new JButton( "View Transcript" );
	public static JButton PII			=new JButton(	"Personal Information" );
	public static JButton PIII			=new JButton(	"Personal Information" );
	public static JButton Logout		=new JButton( "Log out" );
	public static JButton EditbPII 		=new JButton("Edit Personal Information");
	public static String[][] 			courses;
	
	Student(){
		
	}
	
	//interfaces
	
	//1.menue
	public JPanel SMenueInterface( )
	{
		 JPanel SMenueInterface			 = new JPanel( );
		 SMenueInterface.setLayout(	new GridLayout( 8 , 1 ) );
		 SMenueInterface.add( ViewTran );
		 SMenueInterface.add( PII );
		 SMenueInterface.add( Logout );
		 return( SMenueInterface );
	}
	
	
		public JPanel SMenueInterfacee( )
	{
		 JPanel SMenueInterface			 = new JPanel( );
		 SMenueInterface.setLayout(	new GridLayout( 8 , 1 ) );
		 //SMenueInterface.add( ViewTran );
		 SMenueInterface.add( PIII );
		 SMenueInterface.add( Logout );
		 return( SMenueInterface );
	}

	
	//2.PII
	public JPanel PII(String Pinfo)
	{
		//from the server: S;INFO;ID;PersonalName;PersonalEmail;PersonalPhone;UserName
			JPanel PII	=new JPanel();
	      	PII.setLayout( new GridLayout( 10 , 5 ) );
	      	
	      	//ResultSet rs = statement.executeQuery("select * from AccountInfo1 where PersonalId ='5'");
	      	//while (rs.next()) {
	      	String[]    pii           = Pinfo.split(";");
	      	JTextField	Userfullname  = new JTextField(pii[2]);
	      	JTextField	Useremail     = new JTextField(pii[1]);
	      	JTextField	Userphone     = new JTextField(pii[4]);
	      	JTextField	Useraddress   = new JTextField(pii[3]);
			JTextField	PasswordText  = new JTextField("");
			JLabel Useremaillb   = 	new JLabel("Email",10);
			JLabel namelb    = 		new JLabel("Name ");
			JLabel Useraddresslb = new JLabel("Address");
			JLabel Userphonelb   = new JLabel("Phone");
			JLabel PasswordLabel = new JLabel("Password");	
			
			
			PII.add(Useremaillb);
			PII.add(Useremail);
			PII.add(namelb);
			PII.add(Userfullname);
			PII.add(Useraddresslb);
			PII.add(Useraddress);
			PII.add(Userphonelb);
			PII.add(Userphone);	
			//PII.add(PasswordLabel);
			//PII.add(PasswordText);
			PII.add(EditbPII);
	      	
//		    		      connection = DriverManager.getConnection("jdbc:sqlite:/Users/abdalaziz202/MySQLiteDB");
//		    		      Statement statement = connection.createStatement();
//		    		      statement.setQueryTimeout(30);  // set timeout to 30 sec.
//		    		      statement.executeUpdate("update AccountInfo1 set PersonalEmail ='"+Useremail.getText()+"',PersonalName='"+Userfullname.getText()+"',PersonalAddress='"+Useraddress.getText()+"',PersonalPhone='"+Userphone.getText()+"' where PersonalId ='5'");
//		
			return(PII);
	}
	
	public JPanel getaction(String line )
	{
		String[] Line=line.split(";");
		JPanel J=new JPanel();
		if (Line[0].equals("mytranscript")){
			return(ViewTranscript(line));
		}
		
		else if (Line[0].equals("my_info"))
			return( PII(line) );
		else
			return J;
	}
	
	
	public void set_info()
	{
		;
	}
	public String get_Tran(String course)
	{
	
		return("S;"+this.Id+";get_transcript");
	}
	
	 public JPanel ViewTranscript(String line){
		 //String[] line=a.split(";");
			//javax.swing.JScrollPane jScrollPane1 = null ;

		 JPanel Grade=new JPanel();
		 //JScrollPane jpane = new JScrollPane();
		 Grade.setBorder(BorderFactory.createTitledBorder("Transcript"));
		 JPanel temp=new JPanel();
		 String[] tran=line.split(";");
		// System.out.println(line);
		 JScrollPane jpane = new JScrollPane();

		 Grade.setLayout(new GridLayout((tran.length)/5,5));
		 for (int i=1;i<tran.length;i++){
			 JLabel l=new JLabel(tran[i]);
			 l.setForeground(new Color(0x000000));
			 jpane.add(l);
			 Grade.add(l);
		 }
		 //jpane.add(Grade);
		// jScrollPane1.add(temp);
		// Grade.add(jScrollPane1);
		 return(Grade);
   }

}
